package rhc.taskSchedule.commander;

import rhc.discribute.node.commander.Commander;
import rhc.discribute.node.commander.impl.CommanderImpl;
import rhc.discribute.signal.Signal;
import rhc.taskSchedule.command.CommandExecuter;
import rhc.taskSchedule.command.RunningCommandCreater;
import rhc.taskSchedule.command.impl.CommandExecuterImpl;
import rhc.taskSchedule.command.impl.RunningCommandCreaterImpl;
import rhc.taskSchedule.commander.callback.NodeDisConnectSignal;
import rhc.taskSchedule.commander.callback.ReceiveMessageSignal;
import rhc.taskSchedule.taskDistribute.TaskDistribute;
import rhc.taskSchedule.taskDistribute.impl.TaskDistributeImpl;
import rhc.taskSchedule.taskSchedule.schedule.TaskScheduleManage;
import rhc.taskSchedule.taskSchedule.schedule.manage.TaskScheduleManageImpl;
import rhc.taskSchedule.taskSchedule.task.TaskExecuteManage;
import rhc.taskSchedule.taskSchedule.task.manage.TaskExecuteManageImpl;

public class TaskScheduleCommanderExecute {
	
	/**
	 * 分布式节点
	 */
	private Commander distributeNodeCommander;
	
	/**
	 * 任务分发器
	 */
	private TaskDistribute taskDistribute;
	
	/**
	 * 任务执行器管理
	 */
	private TaskExecuteManage taskExecuteManage;
	
	/**
	 * 任务调度器管理
	 */
	private TaskScheduleManage taskScheduleManage;
	
	/**
	 * 命令解析和生产器
	 */
	private RunningCommandCreater runningCommandCreater;
	

	private CommandExecuter commandExecuter;

	private TaskScheduleCommander taskScheduleCommander;
	
	public TaskScheduleCommanderExecute(TaskScheduleCommander taskScheduleCommander,Commander distributeNodeCommander) throws Exception{
		this.taskScheduleCommander=taskScheduleCommander;
		this.distributeNodeCommander=distributeNodeCommander;
		
		runningCommandCreater=new RunningCommandCreaterImpl(this);
		commandExecuter=new CommandExecuterImpl(this);
		taskDistribute=new TaskDistributeImpl(this);
		taskScheduleManage=new TaskScheduleManageImpl(this);
		taskExecuteManage=new TaskExecuteManageImpl(this);
		registerCallback();
	}
	
	/**
	 * 注册消息回调
	 */
	private void registerCallback(){
		ReceiveMessageSignal messageSignal=new ReceiveMessageSignal(commandExecuter);
		
		distributeNodeCommander.getSignalManage().connect(Signal.RECEIVE_MSG, messageSignal);
		
		NodeDisConnectSignal nodeDisConnectSingal=new NodeDisConnectSignal(taskScheduleCommander);
		distributeNodeCommander.getSignalManage().connect(Signal.HOST_REMOVE, nodeDisConnectSingal);
	}

	public Commander getDistributeNodeCommander() {
		return distributeNodeCommander;
	}

	public void setDistributeNodeCommander(Commander distributeNodeCommander) {
		this.distributeNodeCommander = distributeNodeCommander;
	}

	public TaskDistribute getTaskDistribute() {
		return taskDistribute;
	}

	public void setTaskDistribute(TaskDistribute taskDistribute) {
		this.taskDistribute = taskDistribute;
	}

	public TaskExecuteManage getTaskExecuteManage() {
		return taskExecuteManage;
	}

	public void setTaskExecuteManage(TaskExecuteManage taskExecuteManage) {
		this.taskExecuteManage = taskExecuteManage;
	}

	public TaskScheduleManage getTaskScheduleManage() {
		return taskScheduleManage;
	}

	public void setTaskScheduleManage(TaskScheduleManage taskScheduleManage) {
		this.taskScheduleManage = taskScheduleManage;
	}

	public RunningCommandCreater getRunningCommandCreater() {
		return runningCommandCreater;
	}

	public void setRunningCommandCreater(RunningCommandCreater runningCommandCreater) {
		this.runningCommandCreater = runningCommandCreater;
	}

	public CommandExecuter getCommandExecuter() {
		return commandExecuter;
	}

	public void setCommandExecuter(CommandExecuter commandExecuter) {
		this.commandExecuter = commandExecuter;
	}

	public TaskScheduleCommander getTaskScheduleCommander() {
		return taskScheduleCommander;
	}

	public void setTaskScheduleCommander(TaskScheduleCommander taskScheduleCommander) {
		this.taskScheduleCommander = taskScheduleCommander;
	}
	
}
